<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta charset="UTF-8">
    <title>导出excel</title>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport' />
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i">
    <link rel="stylesheet" href="assets/css/ready.css">
</head>
<body>
<div class="wrapper">
    <div class="main-header">
        <div class="logo-header">
            <a href="enterProduct.html" class="logo">
                艾尔之光仓库管理
            </a>
            <button class="navbar-toggler sidenav-toggler ml-auto" type="button" data-toggle="collapse" data-target="collapse" aria-controls="sidebar" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <button class="topbar-toggler more"><i class="la la-ellipsis-v"></i></button>
        </div>
    </div>
    <div class="sidebar">
        <div class="scrollbar-inner sidebar-wrapper">
            <ul class="nav">
                <li class="nav-item">
                    <a href="enterProduct.html">
                        <i class="la la-th"></i>
                        <p>商品录入</p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="enterInventory.html">
                        <i class="la la-th"></i>
                        <p>库存录入</p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="enterPurchase.html">
                        <i class="la la-th"></i>
                        <p>采购预录</p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="enterGoodsArrived.html">
                        <i class="la la-th"></i>
                        <p>采购到货录入</p>
                    </a>
                </li>
                <li class="nav-item active">
                    <a href="export.html">
                        <i class="la la-th"></i>
                        <p>导出Execl</p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="updateSalesperson.html">
                        <i class="la la-th"></i>
                        <p>修改业务员姓名</p>
                    </a>
                </li>
            </ul>
        </div>
    </div>
    <div class="main-panel">
        <div class="content">
            <div class="container-fluid">
                <div class="card">
                    <div class="card-header">
                        <div class="card-title">导出Execl</div>
                    </div>
                    <div class="card-body">
                        <div class="align-content-center">
                            <button id="downloadInventoryExcel" class="btn btn-success">导出库存表Execl</button>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="align-content-center">
                            <button id="downloadPurchaseExcel" class="btn btn-success">导出采购表Execl</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="assets/js/core/jquery.3.2.1.min.js"></script>
<script src="assets/js/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
<script src="assets/js/core/popper.min.js"></script>
<script src="assets/js/core/bootstrap.min.js"></script>
<script src="assets/js/plugin/chartist/chartist.min.js"></script>
<script src="assets/js/plugin/chartist/plugin/chartist-plugin-tooltip.min.js"></script>
<script src="assets/js/plugin/bootstrap-notify/bootstrap-notify.min.js"></script>
<script src="assets/js/plugin/bootstrap-toggle/bootstrap-toggle.min.js"></script>
<script src="assets/js/plugin/jquery-mapael/jquery.mapael.min.js"></script>
<script src="assets/js/plugin/jquery-mapael/maps/world_countries.min.js"></script>
<script src="assets/js/plugin/chart-circle/circles.min.js"></script>
<script src="assets/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js"></script>
<script src="assets/js/ready.min.js"></script>
<script>
    $("#downloadInventoryExcel").click(function (){
        downloadInventoryExcel();
    });

    function downloadInventoryExcel() {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', '/download_inventory_excel', true);
        xhr.responseType = 'blob';
        xhr.onload = function() {
            if (this.status === 200) {
                var blob = this.response;
                var reader = new FileReader();
                reader.readAsDataURL(blob);
                reader.onload = function(e) {
                    var a = document.createElement('a');
                    a.href = e.target.result;
                    console.log(e.target)
                    a.download = '亚马逊成品进出登记库存表.xlsx';
                    document.body.appendChild(a);
                    a.click();
                };
            }
        };
        xhr.send();
    };

    $("#downloadPurchaseExcel").click(function (){
        downloadPurchaseExcel();
    });

    function downloadPurchaseExcel() {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', '/download_purchase_excel', true);
        xhr.responseType = 'blob';
        xhr.onload = function() {
            if (this.status === 200) {
                var blob = this.response;
                var reader = new FileReader();
                reader.readAsDataURL(blob);
                reader.onload = function(e) {
                    var a = document.createElement('a');
                    a.href = e.target.result;
                    console.log(e.target)
                    a.download = '采购信息记录表.xlsx';
                    document.body.appendChild(a);
                    a.click();
                };
            }
        };
        xhr.send();
    }
</script>
</html>